package com.Hsu.blog.model;

import com.Hsu.blog.common.Constants;
import lombok.Data;

/**
 * @author Hsu琛君珩
 * @ClassName:Result
 * @date 2024-01-24
 * @apiNote
 * @Version: v1.0
 */

@Data
public class Result<T> {
    private int code;//200表示成功 -1表示失败
    private String errorMsg;
    private T data;

    public static<T> Result<T> success(T data){
        Result result=new Result();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setData(data);
        return result;
    }

    public static<T> Result<T> fail(String errorMsg){
        Result result=new Result();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setErrorMsg(errorMsg);
        return result;
    }

    public static<T> Result<T> fail(String errorMsg,T data){
        Result result=new Result();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setErrorMsg(errorMsg);
        result.setData(data);
        return result;
    }
}
